#include "hitbox.h"

Hitbox::Hitbox(int x, int y, int w, int h)
{
	xy = new Vector((float)x, (float)y);
	wh = new Vector((float)w, (float)h);
	for(int i=0; i<4; i++)
		worldCoords[i] = 0;
	identifier = "unset";
}
Hitbox::Hitbox()
{
	xy = 0;
	wh = 0;
	for(int i=0; i<4; i++)
		worldCoords[i] = 0;
}
Hitbox::~Hitbox()
{
	if(xy != 0)
		delete xy;
	if(wh != 0)
		delete wh;
}
void Hitbox::setIdentifier(char *str)
{
	identifier = str;
}
void Hitbox::setDimensions(int x, int y, int w, int h)
{
	if(xy != 0)
		delete xy;
	if(wh != 0)
		delete wh;

	xy = new Vector((float)x, (float)y);
	wh = new Vector((float)w, (float)h);
}
void Hitbox::calcWorldCoords(int xoffset, int yoffset, float angle)
{
	float cs = cos(angle);
	float sn = sin(angle);

	worldCoords[0] = new Vector(((cs * -wh->getX() - sn * -wh->getY())+xy->getX()) ,((sn * -wh->getX() + cs * -wh->getY())+xy->getY()));
	worldCoords[1] = new Vector(((cs * -wh->getX() - sn * wh->getY())+xy->getX()),((sn * -wh->getX() + cs * wh->getY())+xy->getY()));
	worldCoords[2] = new Vector(((cs * wh->getX() - sn * wh->getY())+xy->getX()),((sn * wh->getX() + cs * wh->getY())+xy->getY()));
	worldCoords[3] = new Vector(((cs * wh->getX() - sn * -wh->getY())+xy->getX()),((sn * wh->getX() + cs * -wh->getY())+xy->getY()));

	for(int i=0; i<4; i++)
	{
		worldCoords[i]->setX((worldCoords[i]->getX()+xoffset));
		worldCoords[i]->setY((worldCoords[i]->getY()+yoffset));
	}
}
void Hitbox::clearWorldCoords()
{
	for(int i=0; i<4; i++)
		delete worldCoords[i];
}
Vector *Hitbox::getWorldCoord(int i)
{
	return worldCoords[i];
}
